/*
 Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.

 Licensed under the Apache License, Version 2.0 (the "License").
 You may not use this file except in compliance with the License.
 A copy of the License is located at

 http://aws.amazon.com/apache2.0

 or in the "license" file accompanying this file. This file is distributed
 on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 express or implied. See the License for the specific language governing
 permissions and limitations under the License.
 */

#import <Foundation/Foundation.h>


#define CSPLogFormat @"%@ line:%d | %s | "

#define CSPLogError(fmt, ...)    [[CSPLogger defaultLogger] log:CSPLogLevelError format:(CSPLogFormat fmt), [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__]
#define CSPLogWarn(fmt, ...)    [[CSPLogger defaultLogger] log:CSPLogLevelWarn format:(CSPLogFormat fmt), [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__]
#define CSPLogInfo(fmt, ...)    [[CSPLogger defaultLogger] log:CSPLogLevelInfo format:(CSPLogFormat fmt), [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__]
#define CSPLogDebug(fmt, ...)    [[CSPLogger defaultLogger] log:CSPLogLevelDebug format:(CSPLogFormat fmt), [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__]
#define CSPLogVerbose(fmt, ...)    [[CSPLogger defaultLogger] log:CSPLogLevelVerbose format:(CSPLogFormat fmt), [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, __PRETTY_FUNCTION__, ##__VA_ARGS__]


typedef NS_ENUM(NSInteger, CSPLogLevel) {
    CSPLogLevelUnknown = -1,
    CSPLogLevelNone = 0,
    CSPLogLevelError = 1,
    CSPLogLevelWarn = 2,
    CSPLogLevelInfo = 3,
    CSPLogLevelDebug = 4,
    CSPLogLevelVerbose = 5
};

/**
 *  CSPLogger is an utility class that handles logging to the console.
 *  You can specify the log level to control how verbose the output will be.
 */
@interface CSPLogger : NSObject

/**
 *  The log level setting. The default is CSPLogLevelNone.
 */
@property (atomic, assign) CSPLogLevel logLevel;

/**
 *  Returns the shared logger object.
 *
 *  @return The shared logger object.
 */
+ (instancetype)defaultLogger;

/**
 *  Prints out the formatted logs to the console.
 *
 *  @param logLevel The level of this log.
 *  @param fmt      The formatted string to log.
 */
- (void)log:(CSPLogLevel)logLevel
     format:(NSString *)fmt, ... NS_FORMAT_FUNCTION(2, 3);

@end
